package cn.felord.common.service.impl;

import cn.felord.common.entity.SysRole;
import cn.felord.common.mapper.SysRoleMapper;
import cn.felord.common.security.event.UrlRolesRefreshEventPublisherAware;
import cn.felord.common.service.ISysRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author dax
 * @since 2018-09-13
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
    @Resource
    private SysRoleMapper sysRoleMapper;
    @Resource
    private UrlRolesRefreshEventPublisherAware urlRolesRefreshEventPublisherAware;

    @Override
    public Set<SysRole> selectRolesByAntPath(String antPath) {
        return sysRoleMapper.selectRolesByAntPath(antPath);
    }

    @Override
    public Set<String> selectUserRoleByUserId(String userId) {
        return sysRoleMapper.selectUserRoleByUserId(userId);
    }

    @Override
    public Integer saveRole(SysRole sysRole) {
        int insert = sysRoleMapper.insert(sysRole);
        if (insert > 0) {
            urlRolesRefreshEventPublisherAware.refresh();
        }
        return insert;
    }

    @Override
    public IPage<SysRole> selectList(Page<SysRole> page) {
        return sysRoleMapper.selectList(page);
    }
}
